generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl", "linux-musl-openssl-3.0.x"]
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Account {
  id                String  @id @default(cuid())
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?
  access_token      String?
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String?
  session_state     String?
  user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @unique
  userId       String
  expires      DateTime
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([userId], type: Hash)
}

model User {
  id                String               @id @default(cuid())
  name              String?
  nickname          String               @unique
  socialNetworks    UserSessionNetwork[]
  email             String?              @unique
  emailVerified     DateTime?
  userInfo          String?              @db.VarChar(280)
  role              Role                 @default(USER)
  image             String?
  isBlocked         Boolean              @default(false)
  blockReason       String?
  accounts          Account[]
  sessions          Session[]
  lostAndFoundItems LostAndFoundItem[]

  @@index([id], type: Hash)
  @@index([nickname], type: Hash)
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

model UserSessionNetwork {
  id                             String                           @id @default(cuid())
  socialNetwork                  SocialNetwork
  link                           String
  userId                         String
  user                           User                             @relation(fields: [userId], references: [id], onDelete: Cascade)
  lostAndFoundItemSocialNetworks LostAndFoundItemSocialNetworks[]

  @@unique([userId, socialNetwork])
}

enum Role {
  USER
  MODERATOR
  ADMIN
}

model LostAndFoundItem {
  id             String                           @id @default(cuid())
  name           String                           @db.VarChar(100)
  description    String                           @default("") @db.VarChar(512)
  campus         Campus
  reason         PostItemReason
  images         String[]
  userId         String
  user           User                             @relation(fields: [userId], references: [id], onDelete: Cascade)
  socialNetworks LostAndFoundItemSocialNetworks[]
  created        DateTime                         @default(now())
  expires        DateTime                         @default(dbgenerated("NOW() + interval '1 week'"))

  @@index([id], type: Hash)
}

model LostAndFoundItemSocialNetworks {
  id                  String             @id @default(cuid())
  lostAndFoundItemId  String
  lostAndFoundItem    LostAndFoundItem   @relation(fields: [lostAndFoundItemId], references: [id], onDelete: Cascade)
  userSocialNetworkId String
  userSessionNetwork  UserSessionNetwork @relation(fields: [userSocialNetworkId], references: [id], onDelete: Cascade)

  @@unique([lostAndFoundItemId, userSocialNetworkId])
}

enum PostItemReason {
  LOST
  FOUND
}

enum Campus {
  V78
  S20
  V86
  MP1
  SG22
  SHP23
  U7
}

enum SocialNetwork {
  TELEGRAM
  VK
}
